package backtracking_finished;

import java.util.ArrayList;
import java.util.List;

public class T78 {

    List<List<Integer>> ret = new ArrayList<>();
    List<Integer> list = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        //k传入的是集合中的元素个数
        for (int i = 0; i <= nums.length; i++) {
            backtracking(nums, i, 0);
        }
        return ret;
    }

    public void backtracking (int[] nums, int k, int startIndex) {
        if (list.size() == k) {
            ret.add(new ArrayList<>(list));
            return;
        }

        for (int i = startIndex; i < nums.length; i++) {
            list.add(nums[i]);
            backtracking(nums, k, i + 1);
            list.remove(list.size() - 1);
        }
    }

    public static void main(String[] args) {
        T78 t = new T78();
        int[] numbs = new int[] {1,2,3};
        t.subsets(numbs);
        System.out.println(t.ret.toString());
    }

}
